package com.film.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.film.domain.Hobby;
import com.film.domain.User;
import com.film.service.HobbyService;
import com.film.service.UserService;
import com.film.service.impl.HobbyServiceImpl;
import com.film.service.impl.UserServiceImpl;

/**
 * 该控制类用来做页面头部点击基本信息的控制类
 * @author 2119196781
 *
 */
@WebServlet("/userEssential.do")
public class UserEssentialInfoController extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		String uId = request.getParameter("uId");//获取用户的id
		int u_id = Integer.parseInt(uId);
		//通过用户id查询对应的用户
		UserService userService= new UserServiceImpl();
		User user=userService.selectAll(u_id);
		session.setAttribute("userLogin",user);
		//查询所有的爱好（hobby表）
		HobbyService hobbyService = new HobbyServiceImpl();
		List<Hobby> hobbys = hobbyService.selectAllHobby();
		//通过用户的id查询对应的爱好信息
		List<Hobby> hobby = hobbyService.select(u_id);
		List<Integer> userHobbys = new ArrayList<>();
		for(Hobby h:hobby) {
			userHobbys.add(h.getH_id());
		}
		session.setAttribute("user", user);
		session.setAttribute("hobbys", hobbys);
		session.setAttribute("userHobbys", userHobbys);
		response.sendRedirect("userinfor.jsp");
	}

}
